﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NUnit.Framework;
using Spring.Context;
using Spring.Context.Support;
using CondominioG1.Persistencia.NHibernate;
using CondominioG1.Negocio;
using CondominioG1.Dominio;

namespace CondominioG1.Pruebas.TestService
{
    [TestFixture]
    public class TestReservaService
    {
        private IApplicationContext Spring;

        [TestFixtureSetUp]
        public void InicializarPruebas()
        {
            Spring = new XmlApplicationContext(
                "assembly://CondominioG1/CondominioG1/capaPersistencia.xml",
                "assembly://CondominioG1/CondominioG1/capaNegocio.xml"
                );

            // Obtengo una referencia a la clase de negocio a probar
            ReservaService reservaService = (ReservaService)Spring.GetObject("reservaService");
            ViviendaService viviendaService = (ViviendaService)Spring.GetObject("viviendaService");
            ResidenteService residenteService = (ResidenteService)Spring.GetObject("residenteService");
            CuotaService cuotaService = (CuotaService)Spring.GetObject("cuotaService");
            AreaService areaService = (AreaService)Spring.GetObject("areaService");
            //Limpia la base de datos de Condominio
            reservaService.EliminarReservas();
            areaService.EliminarAreas();
            cuotaService.EliminaCuotas();
            viviendaService.EliminarViviendas();
            residenteService.EliminarResidentes();
            //Data para modificar y eliminar usada en las pruebas
            residenteService.RegistrarResidente("40506070", "Leila", "Conde", 31, "lconde@upc.edu.pe", "yurnero", "PROPIETARIO");
            areaService.RegistrarArea("A0001", "Piscina", "A1", 30, "libre");
         }

        [Test]
        public void TestRealizarReserva()
        {
            ReservaService reservaService = (ReservaService)Spring.GetObject("reservaService");
            Assert.NotNull(reservaService);
            Reserva reserva = null;
            Assert.DoesNotThrow(delegate
            {
            reserva = reservaService.RealizarReserva(DateTime.Now, 2, "40506070", "A0001", "Almuerzo Familiar");
            });
            Assert.NotNull(reserva);
            Assert.Greater(reserva.Numero, 0);

        }

        [Test]
        public void TestListarReservas()
        {
            ReservaService reservaService = (ReservaService)Spring.GetObject("reservaService");
            ICollection<Reserva> LReserva = reservaService.ListaReservasActualizada();
            Assert.NotNull(LReserva);
        }

    }
}